#ifndef SOCKET_TOOL_H_
#define SOCKET_TOOL_H_

#include <stddef.h>
#include <sys/types.h>
#include "String.h"
#include <netinet/in.h>

/** 
 * 封装read函数，使得读取到n个字节后才返回
 * date:2025-08-29 14:37
 */
ssize_t readn(int sockfd, char *buf, size_t n);

/**
 * 封装recv函数，使得读取到n个字节后才返回
 * date:2025-8-29 14:51
 */
ssize_t recvn(int sockfd, char *buf, size_t n, int flags);

#define READ_BYTES 64
/**
 * 在tcp socket中读取一行
 * date:2025-08-29 18:21
 */
String* read_tcp_line(int sockfd);

/**
 * 获取换行符的下标
 * date:2025-08-29 18:22
 */
ssize_t terminator_at(const char *buf, size_t len);

/**
 * ipv4地址转为字符串
 * date:2025-08-31 21:11
 */
char* sockaddr_to_string(const struct sockaddr_in* ipv4);

#endif